package TaskStructure
{
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	public class XMLLoader extends Sprite
	{
		// public objects
		private var xmlFile:String;
		public var xml:XML;
		
		public function XMLLoader()
		{
			
		}
		
		/** Call init once COMPLETE event listener is added, initiates loading process */
		public function init(xmlFile:String):void
		{
			this.xmlFile = xmlFile;
			var urlRequest:URLRequest = new URLRequest(xmlFile);
			var urlLoader:URLLoader = new URLLoader();
			urlLoader.addEventListener(Event.COMPLETE, xmlHandler);
			try { 				
				urlLoader.load(urlRequest);
			} catch (e:Error){
				trace("Problem loading ", xmlFile);
			}
		}
		
		private function xmlHandler(e:Event):void
		{
			//urlLoader.removeEventListener(Event.COMPLETE, xmlProblemTemplatesHandler);
			var urlLoader:URLLoader = URLLoader(e.target);
			xml = new XML(urlLoader.data);		
			this.dispatchEvent(new Event(Event.COMPLETE));
		} 
	}
}